import json
import logging
import sys

import click
from rich.logging import RichHandler

try:
    with open('config.json', 'r+', encoding='utf-8') as config_obj:
        application_conf: dict = json.load(config_obj)
except FileNotFoundError:
    logging.error("Please ensure 'config.json' exists.")
    raise sys.exit()


def get_rich_logger():
    if "log_level" in application_conf.keys():
        log_level = application_conf['log_level']
    else:
        log_level = "INFO"

    logging.basicConfig(
        level=log_level,
        format="%(message)s",
        datefmt="[%Y-%m-%d %H:%M:%S]",
        handlers=[RichHandler(rich_tracebacks=True, tracebacks_suppress=[click])]
    )
    logger = logging.getLogger("rich")

    return logger


logger = get_rich_logger()
METASTORE_URL = application_conf['metastore']
http_option = application_conf['deployment']
